
layui.use(['form','layer','element','laydate','laytpl'], function () {

        //显示推广码
        initCode();

});

function initCode(){
    $.ajax({
        url: ctxPath+'report/saler',
        type: 'get',
        dataType: "json",
        success: function (data) {
            if(data.rel){
               console.log(data.result)
                $("#saleTitle").html("今日销售排名("+data.result.saler_report_time+")")
                rankHtml("saler",data.result.saler_report_data,"fa fa-star",5)
            }
        }
    });
}

function rankHtml(el,result,rankStyle,length) {
    var resultHtml="";
    for(var index=0;index<result.length;index++){
        resultHtml+="<tr><td>"+rankStyleHtml(index,length,rankStyle)
            +"</td><td>"+result[index].alians +"</td><td>"
            +toMoney(result[index].saleAmount) +"</td></tr>";
    }
    $("#"+el).html(resultHtml);
}

function rankStyleHtml(i,length,rankStyle) {
    var styleHtml="";
    for(var index=i;index<length;index++){
        styleHtml+="<i class='"+rankStyle+"'></i>";
    }
    return styleHtml;
}

function toMoney(num){
    num = num.toFixed(2);
    num = parseFloat(num)
    num = num.toLocaleString();
    return num;//返回的是字符串23,245.12保留2位小数
}

